package com.ugrow.Study_System.activity;

import android.annotation.TargetApi;
//import android.icu.text.SimpleDateFormat;
import android.net.Uri;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.text.SimpleDateFormat;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import com.ugrow.Study_System.R;

import java.util.ArrayList;
import java.util.Date;

public class TimerActivity extends AppCompatActivity {

    private ArrayList<String> timeAl = new ArrayList<>();
    private ListView timerLv;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;
    private ArrayAdapter<String> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_timer);
        timerLv = (ListView) findViewById(R.id.act_timer_Lv);

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    public void getTimeBtn(View view) {
        //获取当前时间,格式位 年-月-日 时:分:秒:毫秒
        Date date = new Date();
        
//        String dateStr = date.toString();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateStr = sdf.format(date);
//        timeAl.add(dateStr);
        timeAl.add(0,dateStr);//将新数据添加到集合的第一个位置上
        //判空
        if (adapter == null) {
            adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, timeAl);
            timerLv.setAdapter(adapter);
        }else {
            adapter.notifyDataSetChanged();
        }

//        Toast.makeText(TimerActivity.this, dateStr, Toast.LENGTH_SHORT).show();

    }


}
